$scriptDir = (split-path $myinvocation.mycommand.path -parent)

$dir = $env:windir + "\system32\inetsrv"

Set-Location $dir
$apps = .\appcmd.exe list config /section:system.webServer/fastCgi /xml

$phpXml = [xml] $apps;
$applicationNodes = $phpXml.SelectNodes("//application[@fullPath[contains(.,'php-cgi.exe')]]");
$count = [int] $applicationNodes.Count;

if ($count -gt 0)
{
    $phpDir = [System.IO.Path]::GetDirectoryName($applicationNodes.Item(0).fullPath);  
}  

Set-Location $scriptDir

if ($phpDir -ne "")
{	
	$phpIni = [System.IO.Path]::Combine($phpDir, "php.ini");
    
	$phpIniBackup = [System.IO.Path]::Combine($phpDir, "php.ini.bak");
	
	copy $phpIni $phpIniBackup;
	
    ..\..\Common\Set-PrivateProfileString.ps1 "$phpIni" PHP fastcgi.impersonate 1    
    
    ..\..\Common\Set-PrivateProfileString.ps1 "$phpIni" PHP cgi.fix_pathinfo 1	
    
    ..\..\Common\Set-PrivateProfileString.ps1 "$phpIni" PHP cgi.force_redirect 0
    
    ..\..\Common\Set-PrivateProfileString.ps1 "$phpIni" PHP doc_root ""
}
